<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="">
        <el-input
          v-model="queryParams.startSite"
          placeholder="请输入源头站点信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="">
        <el-input
          v-model="queryParams.endSite"
          placeholder="请输入收货站点信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="">
        <el-input
          v-model="queryParams.truckDriver"
          placeholder="请输入车牌/司机/电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="">
        <el-input
          v-model="queryParams.product"
          placeholder="请输入货物名称/编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="" prop="isOverWeight">
        <el-select
          v-model="queryParams.isOverWeight"
          placeholder="请选择是否超载"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择运输状态：运输中、已完成、已作废。。。"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dict.type.freight_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入运输单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:freightOrder:add']"
          >新增发货信息</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:freightOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:freightOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:freightOrder:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="freightOrderList"
      @selection-change="handleSelectionChange"
      border
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" type="index" fixed />
      <!-- <el-table-column label="运输编号唯一" align="center" prop="checkNo" /> -->
      <el-table-column
        label="源头站点名称"
        align="center"
        prop="startSiteName"
        width="120"
        show-overflow-tooltip
      />
      <!-- <el-table-column label="源头站点编号" align="center" prop="startSiteCode" width="120" show-overflow-tooltip/> -->
      <el-table-column
        label="收货站点名称"
        align="center"
        prop="endSiteName"
        width="120"
        show-overflow-tooltip
      />
      <!-- <el-table-column label="收货站点编号" align="center" prop="endSiteCode" width="120" show-overflow-tooltip/> -->

      <el-table-column label="卡车司机" align="center" prop="plate" width="240">
        <template slot-scope="scope">
          <span
            >{{ scope.row.plate }}，{{ scope.row.driverName }}，{{
              scope.row.driverPhone
            }}</span
          >
        </template>
      </el-table-column>

      <!-- <el-table-column label="挂车号" align="center" prop="plateGua" /> -->
      <!-- <el-table-column label="司机姓名" align="center" prop="driverName" /> -->
      <!-- <el-table-column label="身份证" align="center" prop="driverCard" /> -->
      <!-- <el-table-column label="司机电话" align="center" prop="driverPhone" width="100" /> -->
      <el-table-column
        label="货物信息"
        align="center"
        prop="productName"
        width="150"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.productName }}，{{ scope.row.productCode }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="货物编码" align="center" prop="productCode" /> -->
      <el-table-column label="总重/t" align="center" prop="weightSum" />
      <!-- <el-table-column label="车重/t" align="center" prop="weightTruck" /> -->
      <!-- <el-table-column label="出货单价" align="center" prop="productPrice" /> -->
      <!-- <el-table-column label="出货总价" align="center" prop="productTotalPrice" /> -->
      <el-table-column label="净重/t" align="center" prop="weightNet" />
      <el-table-column label="限重/t" align="center" prop="limitWeight" />
      <el-table-column label="是否超载" align="center" prop="isOverWeight">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no"
            :value="scope.row.isOverWeight"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="发车时间"
        align="center"
        prop="startTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="收货时间"
        align="center"
        prop="endTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="运输状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.freight_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="运输单号" align="center" prop="orderNo" />
      <el-table-column label="运输单" align="center" prop="orderImg" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.orderImg" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="运输价" align="center" prop="orderPrice" />
      <el-table-column label="总价" align="center" prop="totalPrice" />
      -->
      <el-table-column
        label="操作"
        fixed="right"
        width="180"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:freightOrder:edit']"
          >修改</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status == '1'"
            @click="handleView(scope.row)"
          >查看</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="
              ['business:freightOrder:ispass'] || scope.row.status == '1'
            "
            @click="handleView(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:freightOrder:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改运输信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      :width="viewPortWidth > 1200 ? 1200 + 'px' : viewPortWidth - 20 + 'px'"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!--
        <el-form-item label="运输编号 唯一" prop="checkNo">
          <el-input v-model="form.checkNo" placeholder="请输入运输编号 唯一" />
        </el-form-item>
        -->

        <el-row :gutter="20">
          <el-col :span="12" :xs="24"> </el-col>
          <el-col :span="12" :xs="24"> </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="源头站点" prop="startSiteCode">
              <el-select
                filterable
                clearable
                v-model="siteFrom1"
                placeholder="请选择"
                @change="handleSiteChange1"
              >
                <el-option
                  v-for="item in siteType1"
                  :key="item.id"
                  :label="item.name + ',' + item.code"
                  :value="item.id"
                >
                  <span style="float: left">{{ item.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                    item.code
                  }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="收货站点" prop="endSiteCode">
              <el-select
                filterable
                clearable
                v-model="siteFrom2"
                placeholder="请选择"
                @change="handleSiteChange2"
              >
                <el-option
                  v-for="item in siteType2"
                  :key="item.id"
                  :label="item.name + ',' + item.code"
                  :value="item.id"
                >
                  <span style="float: left">{{ item.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                    item.code
                  }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="卡车司机" prop="plate">
          <el-select
            filterable
            v-model="truckDriverFrom"
            placeholder="请选择"
            @change="handleTruckDriverChange"
          >
            <el-option
              v-for="item in truckDriverList"
              :key="item.id"
              :label="
                item.plate +
                ',限重：' +
                item.limitWeight +
                ',' +
                item.driverName +
                ',' +
                item.driverPhone
              "
              :value="item.id"
              :style="{
                height: viewPortWidth > 1000 ? '34px' : '105px',
                borderBottom: viewPortWidth > 1000 ? '0' : '1px solid #eee',
              }"
            >
              <div>
                <span style="float: left">车牌：{{ item.plate }}，</span>
                <span style="float: left">皮重：{{ item.weightTruck }}，</span>
                <span style="float: left">限重：{{ item.limitWeight }}，</span>
                <br v-if="viewPortWidth < 1000" />
                <span style="float: left">车型：{{ item.truckType }}，</span>
                <br v-if="viewPortWidth < 1000" />
                <span style="float: left; font-size: 14px"
                  >司机姓名：{{ item.driverName }}，</span
                >
                <span style="float: left; font-size: 14px"
                  >司机电话：{{ item.driverPhone }}</span
                >
              </div>
            </el-option>
          </el-select>
        </el-form-item>

        <!-- <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="车牌号" prop="plate">
              <el-input v-model="form.plate" placeholder="请输入车牌号" />
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="司机姓名" prop="driverName">
              <el-input v-model="form.driverName" placeholder="请输入司机姓名" />
            </el-form-item>
          </el-col>
        </el-row> -->

        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="货物" prop="productCode">
              <el-select
                filterable
                v-model="product"
                placeholder="请选择"
                @change="handleProductChange"
              >
                <el-option
                  v-for="item in productList"
                  :key="item.id"
                  :label="
                    item.name +
                    ',' +
                    item.code +
                    ',品种：' +
                    item.breed +
                    ',定价' +
                    item.price +
                    ',地区' +
                    item.region
                  "
                  :value="item.id"
                >
                  <span style="float: left">名称：{{ item.name }}，</span>
                  <span style="float: left"
                    >编码：{{ item.limitWeight }}，</span
                  >
                  <span style="float: left">品种：{{ item.truckType }}，</span>
                  <span style="float: left; font-size: 14px"
                    >定价：{{ item.price }}，</span
                  >
                  <span style="float: left">地区：{{ item.region }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="总重/t" prop="weightSum">
              <el-input v-model="form.weightSum" placeholder="请输入总重/t" />
            </el-form-item>
          </el-col>
        </el-row>

        <!--
        <el-form-item label="总重/t" prop="weightSum">
          <el-input v-model="form.weightSum" placeholder="请输入总重/t" />
        </el-form-item>
        <el-form-item label="车重/t" prop="weightTruck">
          <el-input v-model="form.weightTruck" placeholder="请输入车重/t" />
        </el-form-item>


        <el-form-item label="出货单价" prop="productPrice">
          <el-input v-model="form.productPrice" placeholder="请输入出货单价" />
        </el-form-item>
        -->
        <!-- <el-form-item label="出货总价" prop="productTotalPrice">
          <el-input v-model="form.productTotalPrice" placeholder="请输入出货总价" />
        </el-form-item>
        <el-form-item label="净重" prop="weightNet">
          <el-input v-model="form.weightNet" placeholder="请输入净重" />
        </el-form-item>
        <el-form-item label="限重" prop="limitWeight">
          <el-input v-model="form.limitWeight" placeholder="请输入/t" />
        </el-form-item>
        -->

        <el-form-item label="运输单号" prop="orderNo">
          <el-input v-model="form.orderNo" />
        </el-form-item>

        <el-form-item label="运输单" prop="orderImg">
          <image-upload v-model="form.orderImg" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="title"
      :visible.sync="openView"
      :width="viewPortWidth > 800 ? 800 + 'px' : viewPortWidth - 20 + 'px'"
      append-to-body
    >
      <el-descriptions
        class="margin-top"
        title=""
        :column="viewPortWidth > 800 ? 2 : 1"
        border
      >
        <el-descriptions-item>
          <template slot="label"> 源头站点 </template>
          {{ form.startSiteName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 收货站点 </template>
          {{ form.endSiteName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 车牌号 </template>
          {{ form.plate }}，{{ form.plateGua }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 司机 </template>
          {{ form.driverName }}，{{ form.driverPhone }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 货物信息 </template>
          {{ form.productName }}，{{ form.productCode }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 定价 </template>
          {{ form.productPrice }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 总重（毛重） </template>
          <el-input-number
            v-if="form.status == '1'"
            v-model="form.weightSum"
            :min="0"
            @change="updateWeightNet"
          />
          <span v-if="form.status == '2'">{{ form.weightSum }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 皮重（车重） </template>
          <el-input-number
            v-if="form.status == '1'"
            v-model="form.weightTruck"
            :min="0"
            @change="updateWeightNet"
          />
          <span v-if="form.status == '2'">{{ form.weightTruck }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 净重（货重） </template>
          <!-- <el-input-number v-if="form.status=='1'" v-model="form.weightNet" :min="0"/> -->
          {{ form.weightNet }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label"> 是否付款 </template>
          <el-radio v-model="form.isPay" label="Y">已付款</el-radio>
          <el-radio v-model="form.isPay" label="N">未付款</el-radio>
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label"> 货运单号 </template>
          {{ form.orderNo }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 货运单 </template>
          <el-image
            :src="baseURL + form.orderImg"
            :preview-src-list="[baseURL + form.orderImg]"
            style="width: 100px; height: 100px"
          ></el-image>
        </el-descriptions-item>
      </el-descriptions>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="passForm"
          v-if="form.status == '1'"
          v-hasPermi="['business:freightOrder:ispass']"
          >收 货</el-button
        >
        <el-button @click="openView = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listFreightOrder,
  getFreightOrder,
  delFreightOrder,
  addFreightOrder,
  updateFreightOrder,
  isPass,
} from "@/api/business/freightOrder";
import { listAllSite } from "@/api/business/site";
import { listAllTruckDriver } from "@/api/business/truckDriver";
import { listAllProduct } from "@/api/business/product";

export default {
  name: "FreightOrder",
  dicts: ["sys_yes_no", "freight_status"],
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 运输信息表格数据
      freightOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openView: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        checkNo: null,
        startSiteCode: null,
        startSiteName: null,
        endSiteCode: null,
        endSiteName: null,
        plate: null,
        plateGua: null,
        driverName: null,
        driverCard: null,
        driverPhone: null,
        weightSum: null,
        weightTruck: null,
        productCode: null,
        productName: null,
        productPrice: null,
        productTotalPrice: null,
        weightNet: null,
        limitWeight: null,
        isOverWeight: null,
        startTime: null,
        endTime: null,
        status: null,
        orderNo: null,
        orderImg: null,
        orderPrice: null,
        totalPrice: null,
      },
      siteFrom1: null,
      siteFrom2: null,
      truckDriverFrom: null,
      product: null,
      // 表单参数
      siteType1: [],
      siteType2: [],
      truckDriverList: [],
      productList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        startSiteCode: [
          { required: true, message: "源头站点信息不能为空", trigger: "blur" },
        ],
        endSiteCode: [
          { required: true, message: "收货站点信息不能为空", trigger: "blur" },
        ],
        plate: [
          { required: true, message: "卡车司机信息不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getSite();
  },
  computed: {
    viewPortWidth() {
      return window.innerWidth || document.documentElement.clientWidth;
    },
  },
  methods: {
    getSite() {
      listAllSite({ type: 1 }).then((response) => {
        this.siteType1 = response.data;
      });
      listAllSite({ type: 2 }).then((response) => {
        this.siteType2 = response.data;
      });

      listAllTruckDriver({}).then((response) => {
        this.truckDriverList = response.data;
      });

      listAllProduct({}).then((response) => {
        this.productList = response.data;
      });
    },

    /** 查询运输信息列表 */
    getList() {
      this.loading = true;
      listFreightOrder(this.queryParams).then((response) => {
        this.freightOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        checkNo: null,
        startSiteCode: null,
        startSiteName: null,
        endSiteCode: null,
        endSiteName: null,
        plate: null,
        plateGua: null,
        driverName: null,
        driverCard: null,
        driverPhone: null,
        weightSum: null,
        weightTruck: null,
        productCode: null,
        productName: null,
        productPrice: null,
        productTotalPrice: null,
        weightNet: null,
        limitWeight: null,
        isOverWeight: null,
        startTime: null,
        endTime: null,
        status: null,
        orderNo: null,
        orderImg: null,
        orderPrice: null,
        totalPrice: null,
      };
      this.siteFrom1 = null;
      this.siteFrom2 = null;
      this.truckDriverFrom = null;
      this.product = null;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加运输信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getFreightOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改运输信息";
      });
    },
    handleView(row) {
      const id = row.id || this.ids;
      getFreightOrder(id).then((response) => {
        this.form = response.data;
        this.openView = true;
        this.title = "运输信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateFreightOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFreightOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    passForm() {
      if (this.form.id != null) {
        isPass({
          id: this.form.id,
          isPay: this.form.isPay,
          weightSum: this.form.weightSum,
          weightNet: this.form.weightNet,
          weightTruck: this.form.weightTruck,
        }).then((response) => {
          this.$modal.msgSuccess("完成收货");
          this.handleQuery();
          this.openView = false;
        });
      }
    },
    updateWeightNet() {
      this.form.weightNet = this.form.weightSum - this.form.weightTruck;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除运输信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delFreightOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    handleSiteChange1(value) {
      if (value) {
        for (let index = 0; index < this.siteType1.length; index++) {
          const id = this.siteType1[index].id;
          if (id === value) {
            this.form.startSiteName = this.siteType1[index].name;
            this.form.startSiteCode = this.siteType1[index].code;
            return;
          }
        }

        // this.siteFrom1 = value
      } else {
        this.siteFrom1 = null;
        this.form.startSiteName = null;
        this.form.startSiteCode = null;
      }
    },
    handleSiteChange2(value) {
      if (value) {
        for (let index = 0; index < this.siteType2.length; index++) {
          const id = this.siteType2[index].id;
          if (id === value) {
            this.form.endSiteName = this.siteType2[index].name;
            this.form.endSiteCode = this.siteType2[index].code;
            return;
          }
        }
      } else {
        this.siteFrom2 = null;
        this.form.endSiteName = null;
        this.form.endSiteCode = null;
      }
    },
    handleTruckDriverChange(value) {
      if (value) {
        for (let index = 0; index < this.truckDriverList.length; index++) {
          const id = this.truckDriverList[index].id;
          if (id === value) {
            // this.form.endSiteName = this.siteType2[index].name;
            // this.form.endSiteCode = this.siteType2[index].code;
            this.form.plate = this.truckDriverList[index].plate;
            this.form.plateGua = this.truckDriverList[index].plateGua;
            this.form.driverName = this.truckDriverList[index].driverName;
            this.form.driverCard = this.truckDriverList[index].driverCard;
            this.form.driverPhone = this.truckDriverList[index].driverPhone;
            this.form.weightTruck = this.truckDriverList[index].weight;
            this.form.limitWeight = this.truckDriverList[index].limitWeight;
            return;
          }
        }
      } else {
        this.form.plate = null;
        this.form.plateGua = null;
        this.form.driverName = null;
        this.form.driverCard = null;
        this.form.driverPhone = null;
        this.form.weightTruck = null;
        this.form.limitWeight = null;
      }
    },
    handleProductChange(value) {
      if (value) {
        for (let index = 0; index < this.productList.length; index++) {
          const id = this.productList[index].id;
          if (id === value) {
            this.form.productCode = this.productList[index].code;
            this.form.productName = this.productList[index].name;
            this.form.productPrice = this.productList[index].price;
            return;
          }
        }
      } else {
        this.form.productCode = null;
        this.form.productName = null;
        this.form.productPrice = null;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "business/freightOrder/export",
        {
          ...this.queryParams,
        },
        `freightOrder_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
